home *** CD-ROM | disk | FTP | other *** search
- Path: news.spies.com!usenet
- From: Erik Max Francis <max@alcyone.com>
- Newsgroups: comp.lang.c++
- Subject: Re: Typecasting a class? Help!
- Date: Sun, 31 Mar 1996 20:58:49 -0800
- Organization: Alcyone Systems
- Message-ID: <315F6289.7D5D01B3@alcyone.com>
- References: <dkelly.828048898@maestro.inav.net>
- NNTP-Posting-Host: newton.alcyone.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.01 (X11; I; Linux 1.2.13 i486)
-
- Dave Kelly wrote:
-
- > Is there any way I can get an instance of MyInt to be seen as
- > and integer to printf without having to explicitly cast it as above?
-
- No. It's because printf (and similar variable-argument functions) do not make
- presumptions about their variable arguments (of which cInteger above is one),
- and therefore cannot know before-the-fact that you want to cast your MyInt
- object to an int object, thereby calling MyInt::operator int.
-
- Your alternatives are either to not use a class, to cast it every time, or to
- use iostreams. (This is the kind of reason iostreams were introduced, after
- all.)
-
- --
- Erik Max Francis &tSftDotIotE && http://www.alcyone.com/max && max@alcyone.com
- San Jose, California, U.S.A. && 37 20 07 N 121 53 38 W && the 4th R is respect
- H.3`S,3,P,3$S,#$Q,C`Q,3,P,3$S,#$Q,3`Q,3,P,C$Q,#(Q.#`-"C`- && 1love && folasade
- Omnia quia sunt, lumina sunt. && Dominion, GIGO, GOOGOL, Omega, Psi, Strategem
- "Out from his breast/his soul went to seek/the doom of the just." -- _Beowulf_
-